#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 1e5 + 10;

int T;
int n, m;
int a[N], c[N];

int main()
{
    freopen("arena.in", "r", stdin);
    freopen("arena.out", "w", stdout);
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++ )
    {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= m; i ++ )
    {
        scanf("%d", &c[i]);
    }
    int num = 0;
    for (int i = 15; i >= 1; i -- )
    {
        if (pow(2, i) <= n)
        {
            num = i;
            break;
        }
    }
    num ++ ;
    string s;
    getchar();
    for (int i = 1; i <= num; i ++ )
    {
        getline(cin, s);
    }
    scanf("%d", &T);
    for (int j = 1; j <= T; j ++ )
    {
        int A, B, C ,D;
        scanf("%d%d%d%d", &A, &B, &C, &D);
        printf("%d\n", n);
    }
    return 0;
}
